class Solution {
    public double myPow(double x, int n) {
        long num = n;
        return num >= 0?pox(x,num) : 1.0/pox(x,-num);
    }

    public double pox(double x,long num) {
        if(num == 0) {
            return 1.0;
        }
        double a = pox(x,num/2);
        return num % 2 == 0 ? a*a : a*a*x;
    }
}